import { reqGetHotelDetailInfo, reqGetBaseName, reqGetBaseRoomsInfo } from '@/api'
const state = {
  detailInfo: {},
  baseName: [],
  baseRoomsInfo1: [],
  baseRoomsInfo2: [],
  baseRoomsInfo3: [],
  baseRoomsInfo4: [],
  baseRoomsInfo5: []
}
const mutations = {
  GETHOTELDETAILINFO(state, detailInfo) {
    state.detailInfo = detailInfo
  },
  GETBASENAME(state, baseName) {
    let map = new Map();
    for (let item of baseName) {
      if (!map.has(item.base_room_name)) {
        map.set(item.base_room_name, item);
      };
    };
    let arr = [...map.values()];
    state.baseName = arr
  },
  GETBASEROOMSINFO(state, { data, i }) {
    if (i == 0) {
      state.baseRoomsInfo1 = [...data]
    } else if (i == 1) {
      state.baseRoomsInfo2 = [...data]
    } else if (i == 2) {
      state.baseRoomsInfo3 = [...data]
    } else if (i == 3) {
      state.baseRoomsInfo4 = [...data]
    } else if (i == 4) {
      state.baseRoomsInfo5 = [...data]
    }
  }
}
const actions = {
  async getHotelDetailInfo({ commit }, id) {
    let result = await reqGetHotelDetailInfo(id)
    // console.log(result);
    if (result.status == 200) {
      commit('GETHOTELDETAILINFO', result.data)
    }
  },
  async getBaseName({ commit }) {
    let result = await reqGetBaseName()
    // console.log(result);
    if (result.status == 200) {
      commit('GETBASENAME', result.data)
    }
  },
  async getBaseRoomsInfo({ commit }, { name, i }) {
    let result = await reqGetBaseRoomsInfo(name)
    // console.log(result, i);
    if (result.status == 200) {
      let data = result.data
      commit('GETBASEROOMSINFO', { data, i })
    }
  }
}
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters
}